stage.create_grid_overlay(50, 'greenyellow')
size = .3
planet = codesters.Sprite("mars", -200, -200)
planet.set_size(.4)
planet.collision_off()
stop1 = codesters.Sprite("codester", -100, -100)
stop1.set_size(size)
stage.set_background("space")
sprite = codesters.Sprite("ufo")
sprite.set_size(0.4)
sprite.go_to(-200, -200)
sprite.pen_down()
sprite.glide_to(-100, -100)
t = codesters.Teacher()
defs = t.find_block('def')
turns = t.find_function('hide')
gotos = t.find_function('go_to')
handlers = t.find_function('event_collision')
try:
tval1 = defs[0][1]
tval2 = t.get_indent_at_line(defs[0][0])
tval2a = defs[0][0]
except:
tval1 = "DNE"
tval2 = "DNE"
tval2a = "DNE"
try:
tval3 = handlers[0][1]
tval4 = t.get_indent_at_line(handlers[0][0])
except:
tval3 = "DNE"
tval4 = "DNE"
try:
tval7 = turns[-1][0]
tval8 = gotos[-1][0]
except:
tval7 = "DNE"
tval8 = "DNE"
def collision(sprite, hit_sprite):
my_var = hit_sprite.get_color()
if my_var == "red":
sprite.say("Ouch!")
if my_var == "green":
sprite.say("Goal!")
# add any other actions...
sprite.event_collision(collision)
t1 = TestObjective()
t1.add_success('collision(sprite, hit_sprite)' in tval1, "Great job!")
t1.add_failure(tval1 == "DNE", "Did you add a Collision event?")
t1.add_failure(('collision(sprite, hit_sprite)' not in tval1 and tval1 != "DNE"), "Try adding a Collision event instead!")
t2 = TestObjective()
t2.add_success('sprite.event_collision(collision)' in tval3 and tval4 == 0, "Great job!")
t2.add_failure(tval3 == "DNE", "Oops! Did you delete the last line of your event?")
t2.add_failure('sprite.event_collision(collision)' not in tval3, "Make sure you've added a Collision.")
t2.add_failure(tval4 > 0, "Oops! Make sure the last line of your event is not indented!")
t3 = TestObjective()
t3.add_success(tval7 > tval2a and tval8 > tval2a and tval7 != "DNE", "Great job!")
t3.add_failure(tval7 == "DNE" or tval8 == "DNE", "Oops! Did you add a Collision event?")
t3.add_failure(tval7 < tval2a or tval8 < tval2a, "Did you add a Collision event?")
t3.add_failure(tval7 == "DNE" or tval8 == "DNE", "Did you add a Collision event?")
tester = TestManager()
tester.add_test_list([t1, t2, t3])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
Submit Work
-
Next Activity
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)